

capture use "data files/sen_r4_local.dta", clear

gen year_survey = 2008
gen round = 4

***********************
***   Demographic   ***
***********************

decode urbrur, gen(urb)
drop urbrur
ren urb urbrur

gen age = Q1 if Q1!=-1 & Q1!=999
label var age "Age of respondent"
drop Q1

decode Q101, gen(gender)
drop Q101
replace gender = "Homme" if gender == "Male"
replace gender = "Femme" if gender == "Female"

gen no_school = 0 if Q89!=-1 & Q89!=. & Q89!=99
replace no_school = 1 if Q89==0 
label var no_school "No formal schooling"
gen informal_school = 0 if Q89!=-1 & Q89!=. & Q89!=99
replace informal_school = 1 if Q89==1 & Q89<=9
label var informal_school "Informal schooling only"

gen primary_school_inc = 0 if Q89!=. & Q89!=99
replace primary_school_inc = 1 if Q89>=2 & Q89<=9
gen primary_school = 0 if Q89!=. & Q89!=99
replace primary_school = 1 if Q89>=3 & Q89<=9
gen secondary_school_inc = 0 if Q89!=. & Q89!=99
replace secondary_school_inc = 1 if Q89>=4 & Q89<=9
gen secondary_school = 0 if Q89!=. & Q89!=99
replace secondary_school = 1 if Q89>=5 & Q89<=9
gen college=  0 if Q89!=. & Q89!=99
replace college = 1 if Q89>=7 & Q89<=9
label var college "Some college, even if incomplete"
drop Q89

gen religion=""
replace religion="None" if Q90==0 | Q90==28 | Q90==29
replace religion="Muslim" if (Q90>=18 & Q90<=24) | Q90==620
replace religion="Christian" if (Q90>=1 & Q90<=13 ) | Q90==30 | Q90==32| Q90==33 | Q90==16 
replace religion="Traditional" if Q90==25
replace religion="Other" if Q90==14  | Q90==15  | Q90==17 | Q90==26  | Q90==780 | Q90==998 | Q90==9999
replace religion="Unkown" if Q90==995  | Q90==9995  | Q90==9998  | Q90==-1
tab Q90 if religion==""

gen ethnicity = Q79
replace ethnicity = . if Q79 >= 990 | Q79 < 0

gen wolof = 0 if ethnicity != .
replace wolof = 1 if ethnicity == 660

gen toucpeul = 0 if ethnicity != .
replace toucpeul = 1 if ethnicity == 661

gen serer = 0 if ethnicity != .
replace serer = 1 if ethnicity == 662

gen bambara = 0 if ethnicity != .
replace bambara = 1 if ethnicity == 663

gen soninke = 0 if ethnicity != .
replace soninke = 1 if ethnicity == 664

gen diola = 0 if ethnicity != .
replace diola = 1 if ethnicity == 665

gen others = 0 if ethnicity != .
replace others = 1 if ethnicity == 668 |  ethnicity == 666 | ethnicity == 669


gen language = Q3

gen french_lang = 0 if language != .
replace french_lang = 1 if language == 2

gen wolof_lang = 0 if language != .
replace wolof_lang = 1 if language == 660

gen toucpeul_lang = 0 if language != .
replace toucpeul_lang = 1 if language == 661

gen serer_lang = 0 if language != .
replace serer_lang = 1 if language == 662

gen mand_lang = 0 if language != .
replace mand_lang = 1 if language == 663 

gen diola_lang = 0 if language != .
replace diola_lang = 1 if language == 665

gen other_lang = 0 if lang != .
replace other_lang = 1 if wolof_lang == 0 & toucpeul_lang == 0 & serer_lang == 0 & mand_lang == 0 & diola_lang == 0


********************
***   Economic   ***
******************** 

gen no_food = 0 if Q8A!=-1 & Q8A!=. & Q8A!=9
replace no_food = 1 if Q8A==2 | Q8A==3 | Q8A==4

gen no_water = 0 if Q8B!=-1 & Q8B!=. & Q8B!=9
replace no_water = 1 if Q8B==2 | Q8B==3 | Q8B==4

gen no_healthcare = 0 if Q8C!=-1 & Q8C!=. & Q8C!=9
replace no_healthcare = 1 if Q8C==2 | Q8C==3 | Q8C==4

gen no_fuel = 0 if Q8D!=-1 & Q8D!=. & Q8D!=9
replace no_fuel = 1 if Q8D==2 | Q8D==3 | Q8D==4

gen no_income = 0 if Q8E!=-1 & Q8E!=. & Q8E!=9
replace no_income = 1 if Q8E==2 | Q8E==3 | Q8E==4
drop Q8A - Q8E

**** Employment variables ***
gen employment_status = "" if Q94!=. & Q94!=-1 & Q94!=9
replace employment_status = "inactive" if  Q94==0
replace employment_status = "unemployed" if Q94==1
replace employment_status = "part-time" if Q94==2 | Q94==3
replace employment_status = "full-time" if Q94==4 | Q94==5
drop Q94 

*** Assets *** 
gen owns_radio = 0 if Q92A!=. & Q92A!=-1 & Q92A!=9
replace owns_radio = 1 if Q92A==1

gen owns_tv = 0 if Q92B!=. & Q92B!=-1 & Q92B!=9
replace owns_tv = 1  if Q92B==1

gen owns_vehicle = 0 if Q92C!=. & Q92C!=-1 & Q92C!=9
replace owns_vehicle = 1  if Q92C==1
drop Q92A-Q92C



**************************
***   Interest index   ***
**************************

gen discuss_pol_index = Q14 if Q14 >= 0 & Q14 <= 2 

gen interest_pub_affairs_index = 0 if Q13 >= 0 & Q13 <= 3
replace interest_pub_affairs_index = 1 if Q13==2 | Q13==3
replace interest_pub_affairs_index = 2 if Q13==3


**** Information and Media ***

gen radio = Q12A if Q12A!=-1 & Q12A!=. & Q12A!=9 & Q12A != 998
gen tv = Q12A if Q12B!=-1 & Q12B!=. & Q12B!=9 & Q12B != 998
gen newspaper = Q12C if Q12C!=-1 & Q12C!=. & Q12C!=9 & Q12C != 998

gen radio_news_often = 0 if Q12A!=-1 & Q12A!=. & Q12A!=9 & Q12A != 998
replace  radio_news_often = 1 if Q12A==4

gen tv_news_often = 0 if Q12B!=-1 & Q12B!=. & Q12B!=9 & Q12B != 998
replace  tv_news_often = 1 if Q12B==4

gen newspaper_news_often = 0 if Q12C !=-1 & Q12C !=. & Q12C !=9 & Q12C != 998
replace  newspaper_news_often = 1 if Q12C ==4


*************************
***   Participation   ***
*************************

gen contact_LG_councilor_index = Q25A if Q25A!=. & Q25A!=-1 & Q25A!=9 & Q25A != 998

gen contact_MP_index = Q25B if Q25B!=. & Q25B!=-1 & Q25B!=9 & Q25B != 998

gen contact_officials_index = Q25C if Q25C!=. & Q25C!=-1 & Q25C!=9 & Q25C != 998

gen att_demonstration_index = Q23C if Q23C!=. & Q23C!=-1 & Q23C!=9 & Q23C != 998

gen raise_issue_index = Q23B  if Q23B!=. & Q23B!=-1 & Q23B!=9 & Q23B != 998

gen vote1 = 0 if Q23D !=-1 & Q23D !=9 &  Q97 !=.
replace vote1 = 1 if Q23D==1

gen close_pds = 0 if Q86 <= 997 & Q86 != . & Q86 != -1
replace close_pds = 1 if Q86 == 660


***********************************
***   Democratic institutions   ***
***********************************


gen trust_EC=Q49C if Q49C!=. & Q49C!=-1 &  Q49C!=9
gen trust_courts=Q49H if Q49H !=. & Q49H !=-1 & Q49H!=9
gen careful_say = Q46 if Q46 !=. & Q46!= -1 & Q46!=9 
gen elections_free_fair = Q71 if Q71 < 8 & Q71 >= 0

gen free_to_speak_mind= 0 if Q15A!=. &   Q15A!=-1
replace free_to_speak_mind= 1 if Q15A==3
replace free_to_speak_mind= 2 if Q15A==4

gen free_to_join_pol_org= 0 if Q15B!=. &   Q15B!=-1
replace free_to_join_pol_org= 1 if Q15B==3
replace free_to_join_pol_org= 2 if Q15B==4

gen free_vote_choice= 0 if Q15C!=. &   Q15C!=-1
replace free_vote_choice= 1 if Q15C==3
replace free_vote_choice= 2 if Q15C==4

gen how_democratic=0 if Q42A!=.  & Q42A!=-1  & Q42A!=9
replace how_democratic=1 if Q42A==3
replace how_democratic=2 if Q42A==4
label var how_democratic "Believe that Senegal is a functioning democracy"

gen satisfaction_democracy = 0 if Q43!=. & Q43!=-1 & Q43!=9
replace satisfaction_democracy = 1 if Q43==3
replace satisfaction_democracy = 2 if Q43==4
label var satisfaction_democracy "Satisfaction democracy"

gen checks_balances =0 if Q33!=. &  Q33!=-1 & Q33!=9
replace checks_balances =1 if Q33==1 |  Q33==2

gen checks_balances_strong =0 if  Q33!=. &  Q33!=-1 & Q33!=9
replace checks_balances_strong =1 if Q33==1
drop Q33

gen against_govt_ban_org=0 if Q19!=-1 & Q19!=. & Q19!=9
replace against_govt_ban_org=1 if Q19==3| Q19==4

gen against_govt_ban_org_str=0 if Q19!=-1 & Q19!=. &Q19!=9
replace against_govt_ban_org_str=1 if Q19==4
drop Q19

gen against_president_discretion =0 if Q37!=. & Q37!=-1 &  Q37!=9
replace against_president_discretion =1 if Q37==3 |  Q37==4

gen against_pres_discr_strong =0 if Q37!=. & Q37!=-1 & Q37!=9
replace against_pres_discr_strong =1 if Q37==4
drop Q37

gen term_limits =0 if Q38!=.  & Q38!=-1  & Q38!=9 
replace term_limits  =1 if Q38 ==1 | Q38 ==2

gen term_limits_strongly =0 if Q38!=.  & Q38!=-1 & Q38!=9 
replace term_limits_strongly  =1 if Q38 ==1
drop Q38

gen opp_parties_criticize =0 if Q34!=. &  Q34!=-1 & Q34!=9
replace opp_parties_criticize =1 if Q34==1 | Q34==2

gen opp_parties_crit_str =0 if Q34!=. &  Q34!=-1 & Q34!=9
replace opp_parties_crit_str =1 if Q34==1

gen media_accountability =0 if Q35!=. &  Q35!=-1 & Q35!=9
replace media_accountability =1 if Q35==1 | Q35==2

gen media_accountability_strong =0 if Q35!=. &  Q35!=-1 & Q35!=9
replace media_accountability_strong =1 if Q35==1
label var media_accountability "Believe media should check government"
drop Q35

gen against_one_party_rule =0 if Q29A!=. & Q29A!=-1 & Q29A!=9
replace against_one_party_rule =1 if Q29A == 1 | Q29A==2

gen a_one_party_rule_strong =0 if Q29A!=. & Q29A!=-1 & Q29A!=9
replace a_one_party_rule_strong =1 if Q29A == 1 

gen reject_military_rule =0 if Q29B!=. & Q29B!=-1 & Q29B!=9
replace reject_military_rule =1 if Q29B == 1 | Q29B==2

gen r_mil_rule_str =0 if Q29B!=. & Q29B!=-1 & Q29B!=9
replace r_mil_rule_str =1 if Q29B == 1

gen reject_one_man_rule =0 if Q29C!=. & Q29C!=-1 &  Q29C!=9
replace reject_one_man_rule =1 if Q29C == 1 | Q29C==2

gen r_one_man_r_strongly =0 if Q29C!=. & Q29C!=-1 & Q29C!=9
replace r_one_man_r_strongly =1 if Q29C == 1 
drop Q29*

gen election_choice_leaders = 0 if Q31!=.  & Q31!=-1  & Q31!=9
replace election_choice_leaders = 1 if Q31==1  | Q31==2

gen election_choice_leaders_str = 0 if Q31!=.  & Q31!=-1  & Q31!=9
replace election_choice_leaders_str = 1 if Q31==1 
drop Q31

gen supports_democracy=0 if Q30!=. & Q30!=-1
replace supports_democracy=1 if Q30==3
label var supports_democracy "Supports democracy"
drop Q30

gen newspaper_free=0 if Q20!=-1 & Q20!=. &Q20!=9
replace newspaper_free=1 if Q20==3 | Q20 ==4 

gen newspaper_free_str=0 if Q20!=-1 & Q20!=. &Q20!=9
replace newspaper_free_str=1 if Q20 ==4
drop Q20



*** Trust in different institutions ***

gen trust_president =Q49A if Q49A!=. & Q49A!=-1 & Q49A!=9

gen trust_national_assembly=Q49B if Q49B!=. &  Q49B!=-1 & Q49B!=9

gen trust_LG_council=Q49D if Q49D!=. & Q49D!=-1 & Q49D!=9

gen trust_ruling_party=Q49E if Q49E!=. & Q49E!=-1 & Q49E!=9

gen trust_opposition_party=Q49F if Q49F!=. & Q49F!=-1 & Q49F!=9

gen trust_traditional_leaders=Q49I if Q49I!=. & Q49I!=-1 & Q49I!=9
drop Q49*

*** Government performance ***

gen present_econ = Q4A - 1 if Q4A!=. & Q4A!=-1 & Q4A!=9
label var present_econ "Economic conditions"

gen personal_econ = Q4B - 1 if Q4B!=. & Q4B!=-1 & Q4B!=9
label var personal_econ "Personal economic conditions"

gen past_econ = Q6A - 1 if Q6A!=. & Q6A!=-1 & Q6A!=9
label var past_econ "Compare econ, past 12mths"

gen future_econ = Q7A - 1 if Q7A!=. & Q7A!=-1 & Q7A!=9
label var future_econ "Future econ (12mth)"

gen handles_economy =Q57A-1 if Q57A!=. & Q57A!=-1 & Q57A!=9
label var handles_economy "Government handles economy"

gen handles_employment=Q57C-1  if Q57C!=. & Q57C!=-1 & Q57C!=9
label var handles_employment "Government handles employment"

gen handles_inflation=Q57D-1 if Q57D!=. & Q57D!=-1 & Q57D!=9
label var handles_inflation "Government handles inflation"

gen handles_inequality=Q57E-1 if Q57E!=. & Q57E!=-1 & Q57E!=9
label var handles_inequality "Government handles inequality"

gen handles_health=Q57G-1 if Q57G!=. & Q57G!=-1 & Q57G!=9
label var handles_health "Government handles health provision"

gen handles_education=Q57H-1 if Q57H!=. & Q57H!=-1 & Q57H!=9
label var handles_education "Government handles education provision"

gen handles_water=Q57I-1 if Q57I!=. & Q57I!=-1 & Q57I!=9
label var handles_water "Government handles water provisoon"
drop Q57*

gen loc_gov_handles_roads=Q59A-1  if Q59A!=. & Q59A!=-1 & Q59A!=9
label var loc_gov_handles_roads "Local government handles roads"

gen loc_gov_handles_markets=Q59B-1  if Q59B!=. & Q59B!=-1 & Q59B!=9
label var loc_gov_handles_markets "Local government handles markets"

gen loc_gov_handles_health=Q59C-1  if Q59C!=. & Q59C!=-1 & Q59C!=9
label var loc_gov_handles_health "Local government handles health in restaurants"

gen loc_gov_handles_clean=Q59D-1  if Q59D!=. & Q59D!=-1 & Q59D!=9
label var loc_gov_handles_clean "Local government handles community cleaning"

gen loc_gov_handles_fees=Q59E-1  if Q59E!=. & Q59E!=-1 & Q59E!=9
label var loc_gov_handles_fees "Local government handles license fees"

gen loc_gov_handles_prop_tax=Q59F-1  if Q59F!=. & Q59F!=-1 & Q59F!=9
label var loc_gov_handles_prop_tax "Local government handles rates on private houses"
drop Q59*

gen performance_president = Q70A-1 if Q70A!=. & Q70A!=-1 & Q70A!=9
label var performance_president "Approves President perfomance"
 
gen performance_mp  = Q70B-1 if Q70B!=. & Q70B!=-1 & Q70B!=9
label var performance_mp "Approves MP perfomance"

gen performance_LG_councilor  = Q70C-1 if Q70C!=. & Q70C!=-1 & Q70C!=9
label var performance_LG_councilor "Approves LG councilor perfomance"
drop Q70*


gen MP_listen = Q54A if Q54A !=. & Q54A !=-1 & Q54A !=9
label var  MP_listen "MPs listen to people's interests"

gen LG_councilor_listen = Q54B if Q54B !=. & Q54B !=-1 & Q54B !=9
label var  LG_councilor_listen "LG Councilors listen to people's interests"
drop Q54*


gen make_LG_councilor_listen = Q24A if Q24A !=. & Q24A !=-1 & Q24A !=9
label var  make_LG_councilor_listen "How likely to make LG Councilors listen"

gen make_MP_listen = Q24B if Q24B !=. & Q24B !=-1 & Q24B !=9
label var make_MP_listen "How likely to make MPs listen"
drop Q24*

gen corruption_president = Q50A if Q50A !=. &  Q50A !=-1 &  Q50A !=9
label var corruption_president "Very corrupt president office"

gen corruption_MP = Q50B if Q50B !=. &  Q50B !=-1 &  Q50B !=9
label var corruption_MP "Very corrupt MPs"

gen corruption_LG_councilors = Q50C if Q50C !=. &  Q50C !=-1 &  Q50C !=9 
label var corruption_LG_councilors "Very corrupt government officials"

gen corruption_government_officials = Q50D if Q50D  !=. &  Q50D  !=-1 &  Q50D  !=9
label var corruption_government_officials "Very corrupt LG councilors"


gen corr_pres_dk = Q50A == 9  if Q50A !=. &  Q50A !=-1
gen corr_mp_dk = Q50B == 9  if Q50B !=. &  Q50B !=-1
gen corr_lg_dk = Q50C == 9  if Q50C !=. &  Q50C !=-1
gen corr_gov_dk = Q50D == 9  if Q50D !=. &  Q50D !=-1


drop eanumb-withinwt


